package com.woniuxy.yoga.admin.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.yoga.admin.dao.model.AdminLoginLog;
import com.woniuxy.yoga.admin.dao.mapper.AdminLoginLogMapper;
import com.woniuxy.yoga.admin.model.form.adminloginlog.SelectAdminLoginLogForm;
import com.woniuxy.yoga.admin.model.param.adminloginlog.SearchLoginLogParam;
import com.woniuxy.yoga.admin.service.AdminLoginLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.yoga.commons.core.model.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 管理员登录日志表 服务实现类
 * </p>
 *
 * @author 韦用文,刘存益,郎腾霄
 * @since 2023年11月28日
 */
@Service
public class AdminLoginLogServiceImpl extends ServiceImpl<AdminLoginLogMapper, AdminLoginLog> implements AdminLoginLogService {

   @Autowired
   private AdminLoginLogMapper adminLoginLogMapper;

    /**
     * 平台查询管理员登录日志
     * @param param
     * @return
     */
    @Override
    public PageInfo searchLoginLog(SearchLoginLogParam param) {
        //创建查询
        QueryWrapper<AdminLoginLog> wrapper = new QueryWrapper<>();
        if (ObjectUtil.isNotEmpty(param.getAccountName()))
            wrapper.like("account_name",param.getAccountName());
        if (ObjectUtil.isNotEmpty(param.getStartTime()))
            wrapper.ge("login_time",param.getStartTime());
        if (ObjectUtil.isNotEmpty(param.getEndTime()))
            wrapper.le("login_time",param.getEndTime());
        wrapper.orderByAsc("log_id");
        //创建分页对象
        Page<AdminLoginLog> page = new Page<>(param.getPageNum()==null?1:param.getPageNum(),param.getPageSize()==null?5:param.getPageSize());
        adminLoginLogMapper.selectPage(page,wrapper);
        PageInfo pageInfo = BeanUtil.toBean(page, PageInfo.class);
        pageInfo.setPages(page.getPages());
        pageInfo.setRecords(page.getRecords());
        return pageInfo;
    }

}
